Ext.define('Role', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
		, "Name"   //名称
		, { name: "Index", type: "int"}   //显示顺序
		, "Flag"   //状态

    ],
    idProperty: "Id"
})


Ext.define('SHApp.Sys.Role.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'widget.rolegrid',
    requires: ['SHApp.Sys.Role.Form'],
    firstLoad: true,
    txtNameID: 'txtName',
    columns: [{
        text: "Id",
        flex: 1,
        dataIndex: 'Id',
        sortable: false,
        hidden: true
    }, {
        text: "名称",
        flex: 1,
        dataIndex: 'Name',
        sortable: true
    }, {
        text: "显示顺序",
        flex: 1,
        dataIndex: 'Index',
        sortable: true,
        hidden: true
    }
    ],
    dataModel: "Role",
    dataUrl:"api/role?format=json",
    hasPageBar: false,
    singleSelect: true,
    initComponent: function () {
        var me = this;
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.btnLockID += me.id;
        me.txtNameID += "Role";
        Ext.apply(this);
        this.creatTbar(); //初始化分页条
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
		            {
		                xtype: 'button',
		                text: '添加',
		                id: me.btnAddID,
		                iconCls: 'icon-btn-add',
		                handler: function () {
		                    var win = me.getForm('SHApp.Sys.Role.Form');
		                    win.loadRecord(new Role());
		                    win.Show("添加");
		                }
		            }, ' ', {
		                xtype: 'button',
		                disabled: true,
		                id: me.btnEditID,
		                text: '修改',
		                iconCls: 'icon-btn-edit',
		                handler: function () {
		                    var rs = me.getSelectionModel().getSelection();
		                    if (rs[0].data.Name == "超级管理员") {
		                        Ext.Msg.alert("提示", "该角色你没有权限修改！");
		                        return;
		                    }
		                    me.EditData(me.getForm('SHApp.Sys.Role.Form'));
		                }
		            }, ' ', {
		                xtype: 'button',
		                disabled: true,
		                id: me.btnDeleteID,
		                text: '删除',
		                iconCls: 'icon-btn-delete',
		                handler: function () {
		                    var rs = me.getSelectionModel().getSelection();
		                    if (rs.length > 0) {
		                        if (rs[0].data.Name == "超级管理员") {
		                            Ext.Msg.alert("提示", "超级管理员不能删除！");
		                            return;
		                        }
		                    }
		                    me.DeleteData();
		                }
		            }
        ];
    }

})

